//
//  AttractionsTableViewCell.m
//  chanyou
//
//  Created by wanli on 15/1/4.
//  Copyright (c) 2015年 wanli. All rights reserved.
//

#import "AttractionsTableViewCell.h"
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
@implementation AttractionsTableViewCell

- (void)dealloc
{
    [_destinations release];
    [_firstImage release];
    [_userName release];
    [_start_date release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.destinations = [[UILabel alloc] init];
        _destinations.font = [UIFont systemFontOfSize:14];
        _destinations.numberOfLines = 0;
        [self.contentView addSubview:_destinations];
        [_destinations release];
//        [self layoutSubviews];
        self.firstImage = [[UIImageView alloc] init];
        [self.contentView addSubview:_firstImage];
//        _firstImage.backgroundColor = [UIColor redColor];
        _firstImage.layer.cornerRadius = 3;
        _firstImage.layer.masksToBounds = YES;
        
        [_firstImage release];
        
    }
    return self;
}

//布局子视图: 1.将当前视图添加到父视图的时候,即cell添加到tableView上 2. 修改当前的frame,即cell得frame
//作用:重新定义子视图的frame.
- (void) layoutSubviews{
    [super layoutSubviews];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:18.0f], NSFontAttributeName, nil];
    CGRect rect = [self.destinations.text boundingRectWithSize:CGSizeMake(self.contentView.frame.size.width - 20, 10000) options:(NSStringDrawingUsesLineFragmentOrigin| NSStringDrawingUsesFontLeading) attributes:dic context:nil];
    
    _height = rect.size.height;
    self.destinations.frame = CGRectMake(10, 5, SCREEN_WIDTH - 30, _height);
    
//    self.destination.backgroundColor = [UIColor redColor];
   
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
